package com.bdy.lm.taximanager.app;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.bdy.lm.taximanager.log.ConfigureLog4J;
import com.bdy.lm.taximanager.log.CrashHandler;
import com.bdy.lm.taximanager.model.Fare;
import com.bdy.lm.taximanager.model.LocationMessageBody;
import com.bdy.lm.taximanager.model.Taxi;
import com.bdy.lm.taximanager.rfid.TotalManager;
import com.bdy.lm.taximanager.util.FileUtils;
import com.bdy.lm.taximanager.util.ReadConfig;
import com.bdy.lm.taximanager.util.ToastUtils;

import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liming on 2016/7/19.
 */
public class MyApp extends Application {

    public static RequestQueue requestQueue;
    public static volatile LocationMessageBody locationMessageBody;
    public static String heartBitUrl = "http://apis.juhe.cn/mobile/get";
    public static String serverUrl = "/TaxiManagerServer/ProcessISURequestServlet";//27.151.118.169:10000//172.16.69.115:8080
    public static String getDriverPhoto = "/TaxiManagerServer/ProcessPhotoServlet?method=getPhoto&ICID=";
    public static String askUrl = "http://api.k780.com:88/?app=weather.today&weaid=101230101&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json";
    public static String locationUrl = "";
    public static volatile int messageSerialNum = 0x0000; //两字节，消息体流水号
    public static int responseSerialNum = 0x0000;//
    public static boolean threadRun = true;
    public static int ISUFlag_1 = 0x10; // 一字节，ISU标识，第一字节为10
    public static int ISUFlag_company_2 = 0x10; // 一字节，ISU标识，产商编号
    public static int ISUFlag_device_3 = 0x00; // 一字节，ISU标识，设备类型
    public static int ISUFlag_serialNum_4 = 0xa0a0a0; // 三字节，ISU标识，序列号
    public static String ISUFlag = "";
    public static String runState = "none";
    public static long startEvaluate = 0;
    public static List data = new ArrayList();
    public static Context context;
    public static Fare fare;
    public static Taxi taxi;
    public static int transitionNum = 0;
    public static String serialName0 = "ttyTCC2";//ttyTCC2   ttyS0
    public static String serialName1 = "ttyS0";
    public static String serialName2 = "", url = "";
    public static int serialBaudRate = 9600;
    private Logger logger;

    @Override
    public void onCreate() {
        super.onCreate();
        TotalManager.instance().start();//RFID
        locationMessageBody = new LocationMessageBody();
        requestQueue = Volley.newRequestQueue(getApplicationContext());
        context = getApplicationContext();
        //System.out.println("系统文件初始化" + FileUtils.fileDirInit());
        if (!FileUtils.fileDirInit()) {
            ToastUtils.showToast("系统文件初始化失败，请重新启动应用！！");
            android.os.Process.killProcess(android.os.Process.myPid());
        }
        //CrashHandler.getInstance().init(this);
        ConfigureLog4J.configure();
        logger = Logger.getLogger(this.getClass());
        ReadConfig.getConfig();
        if (url.equals("") || ISUFlag.equals("")) {
            logger.info("没有配置文件!");
            Log.d("MyApp", "没有配置文件!");
            //没有配置文件则自动退出
            ToastUtils.showToast("没有导入配置文件！");
            android.os.Process.killProcess(android.os.Process.myPid());
        } else {
            serverUrl = url + serverUrl;
            getDriverPhoto = url + getDriverPhoto;
        }
    }
}
